Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closures passed to the skip method are now bound to the test case #338

Merged
merged 4 commits into from
Jul 8, 2021

Conversation

lukeraymonddowning
Copy link
Member

@lukeraymonddowning lukeraymonddowning commented Jul 8, 2021

Q A
Bug fix? no
New feature? yes

Hey y'all,

something that came up in the stream yesterday was this:

public function requiresPostgreSQL(): void
{
    if (DB::getDriverName() !== 'pgsql') {
        $this->markTestSkipped('This test requires a PostgreSQL database connection');
    }
}

Obviously, this condition requires the test case setup method to already have been run, so you wouldn't be able to write it in Pest's skip method. This PR enables this functionality by moving the conditional logic into the HigherOrderMessage itself, and binding the conditional closure to the test case.

it('works when using PostgreSQL', function() {
    expect(true)->toBeTrue();
})->skip(fn() => DB::getDriverName() !== 'pgsql', 'This test requires a PostgreSQL database connection');

This feature actually opens up the potential for other bound callable too, because now when adding to a HigherOrderMessage, you can simply use the newly built when method and pass a conditional; it will always be bound to the test case.

Kind Regards,
Luke

src/Support/HigherOrderMessage.php Outdated Show resolved Hide resolved
src/Support/HigherOrderMessage.php Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants